package com.houtai.service.black;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.houtai.bean.dto.black.TdBlackDetailDto;
import com.houtai.bean.dto.black.TdBlackListDto;
import com.houtai.bean.vo.black.TdBlackDetail;
import com.houtai.bean.vo.black.TdBlackDetailVo;
import com.houtai.bean.vo.black.TdBlackList;
import com.houtai.bean.vo.black.TdBlackListVo;
import com.houtai.dao.TdBlackDao;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlackService {
    private static Logger logger = Logger.getLogger(BlackService.class);
    @Autowired
    private TdBlackDao tdBlackDao;

    /**
     * @Purpose:    黑名单搜索
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     TdBlackListVo
     */
    public TdBlackListVo blackList(TdBlackListDto dto) {
        String logInfo = this.getClass().getName() + ":blackList:";
        TdBlackListVo retInfo = new TdBlackListVo();
        logger.info("======" + logInfo + "begin======");
        try {


            String orderBy = "black_id DESC";

            PageHelper.startPage(dto.getCurrent_page(), dto.getPage_size(), orderBy);
            List<TdBlackList> lists = tdBlackDao.findTdBlackList(dto);
            PageInfo<TdBlackList> list = new PageInfo<>(lists);
            if (list.getTotal() > 0) {
                retInfo.setCurrent_page(dto.getCurrent_page());
                retInfo.setList(list.getList());
                retInfo.setPage_size(list.getPageSize());
                retInfo.setTotal_record(list.getTotal());
                retInfo.setPages(list.getPages());
                retInfo.setMark("0");
                retInfo.setTip("查询成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("无黑名单信息");
            }
        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
    /**
     * @Purpose:    园区指数前十
     * @param:      dto
     * @Version:    1.0
     * @Author:     li
     * @time:       2019/8/21
     * @return:     ArticleListVo
     */
    public TdBlackDetailVo blackDetail(TdBlackDetailDto detailDto) {
        String logInfo = this.getClass().getName() + ":blackDetail:";
        TdBlackDetailVo retInfo = new TdBlackDetailVo();
        logger.info("======" + logInfo + "begin======");
        try {
            TdBlackDetail detail = tdBlackDao.findTdBlackDetail(detailDto);
            if (detail != null) {
                retInfo.setDetail(detail);
                retInfo.setMark("0");
                retInfo.setTip("查询成功");
            } else {
                retInfo.setMark("1");
                retInfo.setTip("无黑名单信息");
            }

        } catch (Exception e) {
            logger.error("======error:" + e.toString() + "======");
            retInfo.setMark("-1");
            retInfo.setTip("系统错误");
        }
        logger.info("======" + logInfo + "end======");
        return retInfo;
    }
}
